//
//  PVThemeCell.m
//  wedding
//
//  Created by 常宽 on 15/1/27.
//  Copyright (c) 2015年 常宽. All rights reserved.
//

#import "PVThemeCell.h"
#import "ThemeModel.h"

#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height

@interface PVThemeCell ()

@property (nonatomic, retain)UIImageView *imageView1;
@property (nonatomic, retain)UIImageView *imageView2;
@property (nonatomic, retain)UIImageView *imageView3;

@end

@implementation PVThemeCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.imageView1 = [[UIImageView alloc] init];
        self.imageView1.tag = 120;
        self.imageView2 = [[UIImageView alloc] init];
        self.imageView2.tag = 121;
        self.imageView3 = [[UIImageView alloc] init];
        self.imageView3.tag = 122;
        [self.contentView addSubview:self.imageView1];
        [self.contentView addSubview:self.imageView2];
        [self.contentView addSubview:self.imageView3];
        self.array = [[NSMutableArray alloc] init];
    }
    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];

    
    for (int i = 0; i < 3; i++) {
        UIImageView *imageView = (UIImageView *)[self.contentView viewWithTag:(i + 120)];
        imageView.frame = CGRectMake(5 + ((WIDTH - 20) / 3 + 5) * i, 5, (WIDTH - 20) / 3, HEIGHT - 10);
        imageView.layer.cornerRadius = 3;
        imageView.clipsToBounds = YES;
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        imageView.userInteractionEnabled = YES;
        imageView.image = [UIImage imageNamed:@"NoPicture.jpg"];
        if (self.array.count != 0) {
            ThemeModel *model = [self.array objectAtIndex:i];
            NSURL *url = [NSURL URLWithString:model.cover_path];
            [imageView sd_setImageWithURL:url];
        }
        
        /// 添加点击事件
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dianjichuanzhi:)];
        [imageView addGestureRecognizer:tap];
    }
}

- (void)dianjichuanzhi:(UITapGestureRecognizer *)tap
{
    ThemeModel *model = [self.array objectAtIndex:tap.view.tag - 120];
    NSLog(@"%@", model.title);
    self.block(model);
    
//    NSLog(@"tap===%d", tap.view.tag);
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
